#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "uthash.h"

#include <iso646.h>

bool isAdditiveNumber(char* num);
bool dfs(char*, int, int, int, int);

int main()
{
	return 0;
}

bool isAdditiveNumber(char* num)
{
	return dfs(num, 0, 0, 0, 0);
}

bool dfs(char* num, int index, int count, int prev2, int prev)
{
	if (!num[index]) return count > 2;

	long cur_num = 0;
	for (int i = index, ch; (ch = num[i]); i++) {
		if (num[index] == '0' && i > index) return false;
		cur_num = cur_num * 10 + ch - '0';

		if (count >= 2) {
			int prev_sum = prev + prev2;
			if (prev_sum < cur_num) return false;
			else if (prev_sum > cur_num) continue;
		}

		if (dfs(num, i + 1, count + 1, prev, cur_num)) return true;
	}
	return false;
}
